package com.qf.bootmr.controller;

import com.qf.bootmr.entity.Pic;
import com.qf.bootmr.entity.Subject;
import com.qf.bootmr.result.R;
import com.qf.bootmr.service.SubjectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-05-26 10:40:55
 */
@RestController
@RequestMapping("subject")
public class SubjectController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectService subjectService;

    /**
     * 通过主键查询单条数据
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Subject selectOne(Integer id) {
        return this.subjectService.queryById(id);
    }

    /**
     * 根据title查询详情
     * @param title
     * @return
     */
    @ApiOperation(value = "queryByTitle",notes = "通过title查询图片信息")
    @GetMapping(value = "/queryByTitle/{title}")
    public R queryByTitle(@PathVariable String title){
        System.out.println("titlt:=="+title);
        List<Subject> titles = subjectService.queryByTitle(title);
        return R.ok().data(titles);
    }

    /**
     * 主页接口
     * @param id
     * @return
     */
    @ApiOperation(value = "queryById",notes = "根据id查询详情")
    @GetMapping(value = "queryById/{id}")
    public R queryById(@PathVariable int id){
        Subject subject = subjectService.queryById(id);
        return R.ok().data(subject);
    }
}
